package com.lanju.app.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.lanju.app.message.bean.B102Request;
import com.lanju.app.message.bean.B102Request.AttachBean;
import com.lanju.app.message.bean.B102Response;
import com.lanju.app.util.AppUtil;
import com.lanju.entity.LanjuAttach;
import com.lanju.entity.User;
import com.lanju.entity.Visit;

/**
 * 拜访门店
 * 
 * @author fly
 *
 */
@Service("B102Service")
public class B102Service extends BaseService<B102Request, B102Response> {

	@Override
	public B102Response doService(B102Request request, User u) throws Exception {
		B102Response res = new B102Response();
		Visit visit = new Visit();
		visit.setUserId(u.getId());
		visit.setShopId(request.getShopId());
		dao.save(visit);
		for (AttachBean bean : request.getAttachs()) {
			LanjuAttach attach = new LanjuAttach();
			attach.setFkId(visit.getId());
			attach.setPath(StringUtils.isBlank(bean.getPath())?"":(AppUtil.oss_psth+bean.getPath()));
			attach.setSeq(bean.getSeq());
			attach.setSuffix(bean.getSuffix());
			attach.setType(LanjuAttach.TYPE_VISIT);
			dao.save(attach);
		}
		res.setVisitId(visit.getId());
		res.setSuccess(true);
		return res;
	}
}
